Array.prototype.unique = function () {
    var res = [];
    var json = {};
    for (var i = 0; i < this.length; i++) {
        if (!json[this[i]]) {
            res.push(this[i]);
            json[this[i]] = 1;
        }
    }
    return res;
}

// 计算当前日期在本年度的周数
Date.prototype.getWeekOfYear = function (weekStart) { // weekStart：每周开始于周几：周日：0，周一：1，周二：2 ...，默认为周日
    weekStart = (weekStart || 0) - 0;
    if (isNaN(weekStart) || weekStart > 6)
        weekStart = 0;

    var year = this.getFullYear();
    var firstDay = new Date(year, 0, 1);
    var firstWeekDays = 7 - firstDay.getDay() + weekStart;
    var dayOfYear = (((new Date(year, this.getMonth(), this.getDate())) - firstDay) / (24 * 3600 * 1000)) + 1;
    return Math.ceil((dayOfYear - firstWeekDays) / 7) + 1;
}

//获取本周是一年中的第几周
function getWeekOfYear(date) {
    var d1 = date;
    var d2 = new Date(date.getFullYear(), 0, 1);
    var d = Math.round((d1 - d2) / 86400000);
    return Math.ceil((d + ((d2.getDay() + 1) - 1)) / 7);
}

/*
 * 毫秒转日期
 */
function MillisecondToDate(msd) {
    var time = parseFloat(msd) / 1000;
    if (null != time && "" != time) {
        if (time > 60 && time < 60 * 60) {
            time = parseInt(time / 60.0) + "分钟" + parseInt((parseFloat(time / 60.0) -
                    parseInt(time / 60.0)) * 60) + "秒";
        } else if (time >= 60 * 60 && time < 60 * 60 * 24) {
            time = parseInt(time / 3600.0) + "小时" + parseInt((parseFloat(time / 3600.0) -
                    parseInt(time / 3600.0)) * 60) + "分钟" +
                parseInt((parseFloat((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60) -
                    parseInt((parseFloat(time / 3600.0) - parseInt(time / 3600.0)) * 60)) * 60) + "秒";
        } else {
            // time = parseInt(time) + "秒";
            time = "----";
        }
    } else {
        time = "----";
    }
    return time;

}

function batchDel(ids, delUrl, back_url) {
    jQuery.confirm({
        title: false,
        content: '您确认要删除选中记录吗?',
        confirmButtonClass: 'btn-info',
        cancelButtonClass: 'btn-warning',
        theme: 'black',
        confirmButton: '确认',
        cancelButton: '取消',
        autoClose: 'cancel|10000',
        confirm: function () {
            jQuery.ajax({
                type: "post",
                traditional: true,
                dataType: 'text',
                async: false,
                data: {
                    id: ids
                },
                url: delUrl,
                success: function (data) {
                    toastMessage(data, back_url);
                }
            });
        }
    });
}

function delFunc(id, delUrl, ele) {
    jQuery.confirm({
        title: false,
        content: '您确认要删除选中记录吗?',
        confirmButtonClass: 'btn-info',
        cancelButtonClass: 'btn-warning',
        theme: 'black',
        confirmButton: '确认',
        cancelButton: '取消',
        autoClose: 'cancel|10000',
        confirm: function () {
            jQuery.ajax({
                type: "post",
                traditional: true,
                dataType: 'text',
                async: false,
                data: {
                    id: id
                },
                url: delUrl,
                success: function (data) {
                    var aj = formatJsonResponse(data);
                    if (aj.code == "200") {
                        pushMessage(aj.message, 'success', 2);
                        $(ele).jqGrid().trigger("reloadGrid");
                    } else {
                        pushMessage(aj.message, 'warning', 2);
                    }
                }
            });
        }
    });
}

function getRoute() {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        url: "../route/getRouteList.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].routeName + ";";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].routeName;
                    }
                }
            }
        }
    });
    return str;
}

function getAllStoreArea() {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        url: "../shelf/getStoreArea.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].name + ";";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].name;
                    }
                }
            }
        }
    });
    return str;
}

function getAllShelf() {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        url: "../shelf/getShelf.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].name + ";";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].name;
                    }
                }
            }
        }
    });
    return str;
}

function getAllCell() {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        url: "../cell/getCell.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].code + ";";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].code;
                    }
                }
            }
        }
    });
    return str;
}

function getBatch() {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        url: "../batch/getBatch?storeAreaId=0",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].name + ";";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].name;
                    }
                }
            }
        }
    });
    return str;
}

function getBatchPlatformList() {
    var str = "";
    jQuery.ajax({
        type: "post",
        url: root + '/batchPlatform/getBatchPlatform.do?batchId=0',
        async: false,
        success: function (json) {
            var jsonobj = eval(json);
            var length = jsonobj.length;
            for (var i = 0; i < length; i++) {
                if (i != length - 1) {
                    str += jsonobj[i].id + ":" + jsonobj[i].name + ";";
                } else {
                    str += jsonobj[i].id + ":" + jsonobj[i].name;
                }
            }
        }
    });
    return str;
}

function getDic(keyNo) {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        data: {
            "keyNo": keyNo
        },
        url: "../dic/getDic.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].keyValue + ":" + jsonobj[i].caption + ";";
                    } else {
                        str += jsonobj[i].keyValue + ":" + jsonobj[i].caption;
                    }
                }
            }
        }
    });
    return str;
}

function getAllUserByRole(roleName) {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        data: {
            "roleName": roleName
        },
        url: "../user/getUserByRole.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].realName + "【" + jsonobj[i].role.roleName + "】;";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].realName + "【" + jsonobj[i].role.roleName + "】";
                    }
                }
            }
        }
    });
    return str;
}

function getAllEscortList() {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        data: {
            roleNameList: "钥匙岗,密码岗"
        },
        url: "../user/getUserByRoleList.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].realName + "【" + jsonobj[i].role.roleName + "】;";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].realName + "【" + jsonobj[i].role.roleName + "】";
                    }
                }
            }
        }
    });
    return str;
}

function getAllKeyByType(keyType) {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        data: {
            "keyType": keyType
        },
        url: "../heavyKey/getAllByType.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].name + ";";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].name;
                    }
                }
            }
        }
    });
    return str;
}

function getAllCarList() {
    var str = "";
    jQuery.ajax({
        type: "post",
        async: false,
        url: "../car/getCarList.do",
        success: function (data) {
            if (data != null) {
                var jsonobj = eval(data);
                var length = jsonobj.length;
                for (var i = 0; i < length; i++) {
                    if (i != length - 1) {
                        str += jsonobj[i].id + ":" + jsonobj[i].license + ";";
                    } else {
                        str += jsonobj[i].id + ":" + jsonobj[i].license;
                    }
                }
            }
        }
    });
    return str;
}

function formatJsonResponse(rs) {
    var aj = {};
    if (rs.responseText) {
        aj = jQuery.parseJSON(rs.responseText);
    } else {
        aj = jQuery.type(rs) === "string" ? jQuery.parseJSON(rs) : rs;
    }
    return aj;
}

function toastMessage(rs, back_url, stayTime) {
    var aj = formatJsonResponse(rs);
    if (aj.code == "200") {
        $().toastmessage('showToast', {
            text: aj.message || "提交成功！",
            stayTime: stayTime || 2000,
            sticky: false,
            position: 'top-center',
            type: 'success',
            close: function () {
                if (back_url != null) {
                    window.location.href = back_url;
                }
            }
        });
        return true;
    } else {
        $().toastmessage('showToast', {
            text: aj.message || "提交失败！",
            stayTime: stayTime || 2000,
            sticky: false,
            position: 'top-center',
            type: 'error',
            close: function () {
                if (back_url != null) {
                    window.location.href = back_url;
                }
            }
        });
        return false;
    }
}

function pushMessage(message, type, stayTime) {
    $().toastmessage('showToast', {
        text: message || "提交成功！",
        stayTime: stayTime * 1000 || 2000,
        sticky: false,
        position: 'top-center',
        type: type || 'notice',
        close: function () {
            $("html").hideLoading();
        }
    });
}

function style_edit_form(form) {
    form.find('input[name=sdate]').datepicker({
        format: 'yyyy-mm-dd',
        autoclose: true
    })
        .end().find('input[name=stock]')
        .addClass('ace ace-switch ace-switch-5').after('<span class="lbl"></span>');
    var buttons = form.next().find('.EditButton .fm-button');
    buttons.addClass('btn btn-sm').find('[class*="-icon"]').hide(); //ui-icon, s-icon
    buttons.eq(0).addClass('btn-primary').prepend('<i class="ace-icon fa fa-check"></i>');
    buttons.eq(1).prepend('<i class="ace-icon fa fa-times"></i>')

    buttons = form.next().find('.navButton a');
    buttons.find('.ui-icon').hide();
    buttons.eq(0).append('<i class="ace-icon fa fa-chevron-left"></i>');
    buttons.eq(1).append('<i class="ace-icon fa fa-chevron-right"></i>');
}

function style_delete_form(form) {
    var buttons = form.next().find('.EditButton .fm-button');
    buttons.addClass('btn btn-sm btn-white btn-round').find('[class*="-icon"]').hide(); //ui-icon, s-icon
    buttons.eq(0).addClass('btn-danger').prepend('<i class="ace-icon fa fa-trash-o"></i>');
    buttons.eq(1).addClass('btn-default').prepend('<i class="ace-icon fa fa-times"></i>')
}

function style_search_filters(form) {
    form.find('.delete-rule').val('X');
    form.find('.add-rule').addClass('btn btn-xs btn-primary');
    form.find('.add-group').addClass('btn btn-xs btn-success');
    form.find('.delete-group').addClass('btn btn-xs btn-danger');
}

function style_search_form(form) {
    var dialog = form.closest('.ui-jqdialog');
    var buttons = dialog.find('.EditTable')
    buttons.find('.EditButton a[id*="_reset"]').addClass('btn btn-sm btn-info').find('.ui-icon').attr('class', 'ace-icon fa fa-retweet');
    buttons.find('.EditButton a[id*="_query"]').addClass('btn btn-sm btn-inverse').find('.ui-icon').attr('class', 'ace-icon fa fa-comment-o');
    buttons.find('.EditButton a[id*="_search"]').addClass('btn btn-sm btn-purple').find('.ui-icon').attr('class', 'ace-icon fa fa-search');
}

function beforeDeleteCallback(e) {
    var form = $(e[0]);
    if (form.data('styled'))
        return false;

    form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
    style_delete_form(form);

    form.data('styled', true);
}

function beforeEditCallback(e) {
    var form = $(e[0]);
    form.closest('.ui-jqdialog').find('.ui-jqdialog-titlebar').wrapInner('<div class="widget-header" />')
    style_edit_form(form);
}

function updatePagerIcons(table) {
    var replacement = {
        'ui-icon-seek-first': 'ace-icon fa fa-angle-double-left bigger-140',
        'ui-icon-seek-prev': 'ace-icon fa fa-angle-left bigger-140',
        'ui-icon-seek-next': 'ace-icon fa fa-angle-right bigger-140',
        'ui-icon-seek-end': 'ace-icon fa fa-angle-double-right bigger-140'
    };
    $('.ui-pg-table:not(.navtable) > tbody > tr > .ui-pg-button > .ui-icon').each(function () {
        var icon = $(this);
        var $class =
            jQuery.trim(icon.attr('class').replace('ui-icon', ''));

        if ($class in
            replacement
        )
            icon.attr('class', 'ui-icon ' + replacement[$class]);
    })
}

function enableTooltips(table) {
    $('.navtable .ui-pg-button').tooltip({
        container: 'body'
    });
    $(table).find('.ui-pg-div').tooltip({
        container: 'body'
    });
}

var myAcX;
function openRfid() {
    try {
        if (myAcX == null) {
            myAcX = new ActiveXObject("WriteReadCarddll.ComWriteReadCard");
        }
        var open = myAcX.IsOpen;
        if (open == false) {
            if (myAcX.Open(1) == false) {
                pushMessage("打开读卡器失败！", 'notice', 2);
                return;
            }
        }
    } catch (e) {
    }
}

var flag = false;
function writeRfid(rfid) {
    try {
        var ret = myAcX.WriteEpc(rfid);
        //var rfid = myAcX.GetEpcCode();
        //if (rfid != null) {
        //    jQuery("#rfid").val(rfid);
        //}
        if (ret == "0：成功") {
            jQuery("#rfid").val(rfid);
            pushMessage("写入完成！", 'notice', 2);
            flag = true;
            jQuery("#btn2").attr("disabled", false);
        } else {
            pushMessage(ret, 'notice', 2);
        }
    } catch (e) {
        pushMessage(e.description, 'notice', 2);
    }
}

function GetDateStr(AddDayCount) {
    var dd = new Date();
    dd.setDate(dd.getDate() + AddDayCount);//获取AddDayCount天后的日期
    var y = dd.getFullYear();
    var m = dd.getMonth() + 1;//获取当前月份的日期
    if (m > 0 && m < 10) {
        m = "0" + m;
    }
    var d = dd.getDate();
    return y + "-" + m + "-" + d;
}

/**
 *  返回某年某月周次范围
 *  @param year  年份
 *  @param weeks 周次
 *  @return  返回周次的日期范围
 */
function getXDate(year, weeks) {
    var date = new Date(year, "0", "1");
    var time = date.getTime();
    // 获取当前星期几，0：星期一 。。。。
    var _week = date.getDay();
    //当这一年的1月1日为周日时则本年有54周，否则没有54周，没有则去除第54周的提示
    if (_week != 0) {//一年53周情况
        if (weeks == 54) {
            return '今年没有54周';
        }
        var cnt = 0;// 获取距离周末的天数
        if (_week == 0) {
            cnt = 7;
        } else if (_week == 1) {
            cnt = 6;
        } else if (_week == 2) {
            cnt = 5;
        } else if (_week == 3) {
            cnt = 4;
        } else if (_week == 4) {
            cnt = 3;
        } else if (_week == 5) {
            cnt = 2;
        } else if (_week == 6) {
            cnt = 1;
        }
        cnt += 1;//加1表示以星期一为一周的第一天
        // 将这个长整形时间加上第N周的时间偏移
        time += cnt * 24 * 3600000; //第2周开始时间

        var nextYear = new Date(parseInt(year, 10) + 1, "0", "1");
        var nextWeek = nextYear.getDay();
        var lastcnt = 0;//获取最后一周开始时间到周末的天数
        if (nextWeek == 0) {
            lastcnt = 6;
        } else if (nextWeek == 1) {
            lastcnt = 0;
        } else if (nextWeek == 2) {
            lastcnt = 1;
        } else if (nextWeek == 3) {
            lastcnt = 2;
        } else if (nextWeek == 4) {
            lastcnt = 3;
        } else if (nextWeek == 5) {
            lastcnt = 4;
        } else if (nextWeek == 6) {
            lastcnt = 5;
        }
        if (weeks == 1) {//第1周特殊处理
            // 为日期对象 date 重新设置成时间 time
            var start = date.Format("yyyy-MM-dd");
            date.setTime(time - 24 * 3600000);
            return start + '~' + date.Format("yyyy-MM-dd");
        } else if (weeks == 53) {//第53周特殊处理
            var start = time + (weeks - 2) * 7 * 24 * 3600000; //第53周开始时间
            var end = time + (weeks - 2) * 7 * 24 * 3600000 + lastcnt * 24 * 3600000 - 24 * 3600000; //第53周结束时间
            // 为日期对象 date 重新设置成时间 time
            date.setTime(start);
            var _start = date.Format("yyyy-MM-dd");
            date.setTime(end);
            var _end = date.Format("yyyy-MM-dd");
            return _start + '~' + _end;
        } else {
            var start = time + (weeks - 2) * 7 * 24 * 3600000; //第n周开始时间
            var end = time + (weeks - 1) * 7 * 24 * 3600000 - 24 * 3600000; //第n周结束时间
            // 为日期对象 date 重新设置成时间 time
            date.setTime(start);
            var _start = date.Format("yyyy-MM-dd");
            date.setTime(end);
            var _end = date.Format("yyyy-MM-dd");
            return _start + '~' + _end;
        }
    } else {//一年54周情况
        var cnt = 0;// 获取距离周末的天数
        if (_week == 0 && weeks == 1) {//第一周
            cnt = 0;
        } else if (_week == 0) {
            cnt = 7;
        } else if (_week == 1) {
            cnt = 6;
        } else if (_week == 2) {
            cnt = 5;
        } else if (_week == 3) {
            cnt = 4;
        } else if (_week == 4) {
            cnt = 3;
        } else if (_week == 5) {
            cnt = 2;
        } else if (_week == 6) {
            cnt = 1;
        }
        cnt += 1;//加1表示以星期一为一周的第一天
        // 将这个长整形时间加上第N周的时间偏移
        time += 24 * 3600000; //第2周开始时间

        var nextYear = new Date(parseInt(year, 10) + 1, "0", "1");
        var nextWeek = nextYear.getDay();
        var lastcnt = 0;//获取最后一周开始时间到周末的天数
        if (nextWeek == 0) {
            lastcnt = 6;
        } else if (nextWeek == 1) {
            lastcnt = 0;
        } else if (nextWeek == 2) {
            lastcnt = 1;
        } else if (nextWeek == 3) {
            lastcnt = 2;
        } else if (nextWeek == 4) {
            lastcnt = 3;
        } else if (nextWeek == 5) {
            lastcnt = 4;
        } else if (nextWeek == 6) {
            lastcnt = 5;
        }

        if (weeks == 1) {//第1周特殊处理
            // 为日期对象 date 重新设置成时间 time
            var start = date.Format("yyyy-MM-dd");
            date.setTime(time - 24 * 3600000);
            return start + '~' + date.Format("yyyy-MM-dd");
        } else if (weeks == 54) {//第54周特殊处理
            var start = time + (weeks - 2) * 7 * 24 * 3600000; //第54周开始时间
            var end = time + (weeks - 2) * 7 * 24 * 3600000 + lastcnt * 24 * 3600000 - 24 * 3600000; //第53周结束时间
            // 为日期对象 date 重新设置成时间 time
            date.setTime(start);
            var _start = date.Format("yyyy-MM-dd");
            date.setTime(end);
            var _end = date.Format("yyyy-MM-dd");
            return _start + '~' + _end;
        } else {
            var start = time + (weeks - 2) * 7 * 24 * 3600000; //第n周开始时间
            var end = time + (weeks - 1) * 7 * 24 * 3600000 - 24 * 3600000; //第n周结束时间
            // 为日期对象 date 重新设置成时间 time
            date.setTime(start);
            var _start = date.Format("yyyy-MM-dd");
            date.setTime(end);
            var _end = date.Format("yyyy-MM-dd");
            return _start + '~' + _end;
        }
    }
}

function formatCurrency(val) {
    var reg = /[\u4e00-\u9fa5]/g;
    var result = val.match(reg);
    var chinese = "";
    jQuery.each(result, function (i, item) {
        chinese += item;
    });
    var number = val.replace(chinese, "");
    if (chinese.indexOf("角") >= 0) {
        number = number / 10;
    }
    return number;
}

//格式化null值
function nullFormatter(cellvalue, options, rowObject) {
    if (cellvalue === undefined || cellvalue === '' || cellvalue === 'NULL') {
        cellvalue = '--';
    }

    return cellvalue;
}

//审核任务
function auditTask(proDefId, taskId, businessKey, executionId, proInsId, type, formUrl) {
    var index = businessKey.indexOf("$");
    var key = businessKey.substring(index + 1);
    var param = "proDefId=" + proDefId + "&taskId=" + taskId + "&businessKey=" + key +
        "&executionId=" + executionId + "&proInsId=" + proInsId + "&type=" + type;
    var url = root + "/" + formUrl + "?" + param;
    window.open(url, "审核任务", "left=0,top=0,width=" + (screen.availWidth - 10) + ",height=" + (screen.availHeight - 50) + ",scrollbars,resizable=yes,toolbar=no");
}

//js获取日期：前天、昨天、今天、明天、后天
function getDay(day) {
    var today = new Date();
    var targetday_milliseconds = today.getTime() + 1000 * 60 * 60 * 24 * day;
    today.setTime(targetday_milliseconds); //注意，这行是关键代码

    var tYear = today.getFullYear();
    var tMonth = today.getMonth();
    var tDate = today.getDate();
    tMonth = doHandleMonth(tMonth + 1);
    tDate = doHandleMonth(tDate);
    return tYear + "-" + tMonth + "-" + tDate;
}

function doHandleMonth(month) {
    var m = month;
    if (month.toString().length == 1) {
        m = "0" + month;
    }
    return m;
}

function formatMoney(number, places, symbol, thousand, decimal) {
    number = number || 0;
    places = !isNaN(places = Math.abs(places)) ? places : 2;
    symbol = symbol !== undefined ? symbol : "";
    thousand = thousand || ",";
    decimal = decimal || ".";
    var negative = number < 0 ? "-" : "",
        i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + "",
        j = (j = i.length) > 3 ? j % 3 : 0;
    return symbol + negative + (j ? i.substr(0, j) + thousand : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : "");
}

//字符串逆转
function strturn(str) {
    if (str != "") {
        var str1 = "";
        for (var i = str.length - 1; i >= 0; i--) {
            str1 += str.charAt(i);
        }
        return (str1);
    }
}
//取文件后缀名
function GetFileExt(filepath) {
    if (filepath != "") {
        var pos = "." + filepath.replace(/.+\./, "");
        return pos;
    }
}
//取文件名不带后缀
function GetFileNameNoExt(filepath) {
    var pos = strturn(GetFileExt(filepath));
    var file = strturn(filepath);
    var pos1 = strturn(file.replace(pos, ""));
    var pos2 = GetFileName(pos1);
    return pos2;

}
//取文件全名名称
function GetFileName(filepath) {
    if (filepath != "") {
        var names = filepath.split("\\");
        return names[names.length - 1];
    }
}

//获得某月的天数
function getMonthDays(year, month) {
    month = parseInt(month, 10);
    var d = new Date(year, month, 0);
    return d.getDate();
}

function getMonthDateRange(year, month) {
    var days = getMonthDays(year, month);//获取当月总共有多少天
    var monthStartDate = year + "-" + month + "-" + 1;
    var monthEndDate = year + "-" + month + "-" + days;
    return monthStartDate + '~' + monthEndDate;
}